#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require_relative '../lib/shell'
require_relative '../lib/git'
require_relative '../lib/packages'

with_ruby_dependencies = true

OptionParser.new do |opts|
  opts.banner = '安装 Rbenv 和它的插件'

  opts.on('-d', '--without-ruby-dependencies', '不安装 ruby 依赖，默认这是要安装的') do
    with_ruby_dependencies = false
  end
end.parse!

git.clone_or_skip 'https://github.com/rbenv/rbenv.git', '~/.rbenv'
git.clone_or_skip 'https://github.com/rbenv/ruby-build.git', '~/.rbenv/plugins/ruby-build'
git.clone_or_skip 'https://github.com/rkh/rbenv-update.git', '~/.rbenv/plugins/rbenv-update'
git.clone_or_skip 'https://github.com/AndorChen/rbenv-china-mirror.git', '~/.rbenv/plugins/rbenv-china-mirror'

shell.rc_append 'export PATH="$HOME/.rbenv/bin:$PATH"'
shell.rc_append 'eval "$(rbenv init -)"'

if with_ruby_dependencies
  packages.install %w[
    gcc automake gdbm-devel libffi-devel libyaml-devel libopenssl-devel make ncurses-devel readline-devel zlib-devel
  ]
end
